package com.xz.group12306.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.xz.group12306.business.service.ManagerService;
import com.xz.group12306.business.service.impl.ManagerServiceImpl;
import com.xz.group12306.domain.User;
/**
 * 管理员增加用户信息  顾赛男  整合  
 */
@WebServlet("/AdminServlet")
public class AdminServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * 构造方法
	 */
	public AdminServlet() {
		super();
	}

	/**
	 * doGet方法
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * doPost方法
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doUserAdd(request, response);
	}
	
	/**
	 * 管理员增加用户记录的方法  顾赛男  整合  
	 */
	protected void doUserAdd(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		PrintWriter out=response.getWriter();
		String userName=request.getParameter("userName");
		String password=request.getParameter("password");
		String rule=request.getParameter("Rule");
		String RealName=request.getParameter("RealName");
		String sex=request.getParameter("adminFlag");
		String city=request.getParameter("City");
		String CertType=request.getParameter("CertType");
		String cert=request.getParameter("cert");
		//String birthday=request.getParameter("birthday");
		
		System.out.println(userName);
		User user=new User();
		user.setUsername(userName);
		user.setPassword(password);
		user.setRule(rule);
		user.setRealname(RealName);
		user.setSex(sex);
		user.setCity(city);
		user.setCertType(CertType);
		user.setCert(cert);
		/*if(!TextUtils.isEmpty(birthday)) {
			user.setBirthday(Date.valueOf(birthday));
		}*/
		ManagerService managerService=new ManagerServiceImpl();
		managerService.addUser(user);
	    out.print("插入成功");
	
	
	List<User> users = managerService.findAllList();
	HttpSession session = request.getSession();

	session.setAttribute("users", users);
	response.sendRedirect("admin/ManageInfo.jsp");
	
	


	
	
	
	}
}
